package com.example.network;

import org.apache.http.HttpConnection;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created with IntelliJ IDEA.
 * User: Jasic_Work
 * Date: 12-9-14
 * To change this template use File | Settings | File Templates.
 */
public class FileDownloader {


    private URL url;

    public String download(String urlStr){

        StringBuilder sb = new StringBuilder();

        String line = null;

        BufferedReader bufferedReader = null;

        try {
            this.url = new URL(urlStr);

            HttpURLConnection httpURLConnection = (HttpURLConnection)this.url.openConnection();

            httpURLConnection.connect();
            bufferedReader = new BufferedReader((new InputStreamReader(httpURLConnection.getInputStream())));

            while((line = bufferedReader.readLine()) != null){
                sb.append(line);
            }

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }


        return sb.toString();
    }
}
